<?php
class Test extends IController{
    public function add(){
        $this->redirect('add');
    }
    public function add_do(){
        $model = new IModel('new');
        $name = IFilter::act(IReq::get('name','post'));
        $pwd = IFilter::act(IReq::get('pwd','post'));
        $data_info = array('name' => $name,'pwd'=>$pwd);
        $model->setData($data_info);
        $res = $model->add();
        if($res)
        {
            $this->redirect('show');
        }

    }
    public function tianjia()
    {
        $model = new IModel("dijiu");
        $name = IReq::get("name");
        $pwd = IReq::get("pwd");
        $res = array('name' => $name,'pwd' =>$pwd);
        $model->setData($res);
        $data = $model->add();
        if($data)
        {
            $this->redirect("shows");
        }
    }
    public function shows()
    {
        $model = new IModel("dijiu");
        $data = $model->query();
        $this->data = $data;
        $this->redirect("shows");
    }
    public function delete()
    {
        $model = new IModel("dijiu");
        $id = IReq::get("id");
        $res = $model->del('id='.$id);
        if($res)
        {
            $this->redirect("shows");
        }

    }
    public function show(){

        $model =new IModel('new');
        $data = $model->query();
        $this->data = $data;
        $this->redirect('show');
    }
    //第三方qq
    public function qq_login(){
        $appid='101353491';			// APPID
        $appkey='df4e46ba7da52f787c6e3336d30526e4';			// APPKEY
        $redirect_uri='http://www.iwebshop.com/index.php';		// 回调地址

        $state = rand(1000,9999);
        $url = " https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=$appid&redirect_uri=$redirect_uri&state=$state";
        header("Location:$url");
    }
    public function map()
    {
        $address = IReq::get("address");
        $ak = "SUORwqL3NalUxZ5uAXaXAxvEfIpS30nc";
        $url = "http://api.map.baidu.com/geocoder/v2/?address=$address&output=json&ak=$ak";
        $data = file_get_contents($url);
        $res = json_decode($data,true);
        $ress = array('lng'=>$res['result']['location']['lng'],'lat'=>$res['result']['location']['lat']);
        echo json_encode($ress);
    }
    //接受qqq.html传过来的文件
    public function bigfile(){

        $file = $_FILES['sliceFile'];
//        print_r($file);die;
        $tmp_name = $file['tmp_name'];
//        print_r($tmp_name);die;
        $sliceNo = $_POST['sliceNo'];
        $blob_count = $_POST['blob_count'];
        $filename = $_POST['filename'];
        $this->movesliceFile($tmp_name,$filename,$sliceNo);
if($blob_count == $sliceNo)
{
    $this->mergeslicecFile($sliceNo,$filename,$tmp_name);
    $this->deletesliceFile($sliceNo,$filename);
}

    }
   public function movesliceFile($tmp_name,$filename,$sliceNo){
        $destination = 'upload/video/'.$filename."_".$sliceNo;
        move_uploaded_file($tmp_name,$destination);
//        print_r($destination);die;
   }
   public function mergeslicecFile($sliceNo,$filename,$tmp_name){
        $data = "";
        for ($i=1;$i<=$sliceNo;$i++)
        {
            $path = 'upload/video/'.$filename."_".$i;
            $data .= file_get_contents($path);
        }
//        print_r($data);
        $new_path = "upload/video/".$filename;
        file_put_contents($new_path,$data);
   }
   public function deletesliceFile($sliceNo,$filename){
        for ($i=1;$i<=$sliceNo;$i++)
        {
            $file = "upload/video/".$filename."_".$i;
            unlink($file);
        }
   }

    public function arre()
    {
        $address = IReq::get("address");
        $ak = "SUORwqL3NalUxZ5uAXaXAxvEfIpS30nc";
        $url = "http://api.map.baidu.com/geocoder/v2/?address=$address&output=json&ak=$ak";
        $data = file_get_contents($url);
        $res = json_decode($data,true);
        $ress = array('lng' => $res['result']['location']['lng'],'lat' => $res['result']['location']['lat']);
        echo json_encode($ress);

    }
}

?>